<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:th='http://www.thymeleaf.org'>

<head>
	<meta charset='UTF-8'/>
	<link rel='stylesheet' type='text/css' href='themes/material/easyui.css'/>
	<link rel='stylesheet' type='text/css' href='themes/icon.css'/>
	<link rel='stylesheet' type='text/css' href='css/style.css'/>
</head>

<body>
	<div id='toolbar' class='top'><ul style='padding-left:5px'><li th:each='btn:${btnlist}'>
		<a href='#' class='easyui-linkbutton' plain='true' onclick='' th:attrappend='onclick=${btn.btnfunc}'>
		<i class='fa fa-' th:attrappend='class=${btn.btnicon}'></i>&nbsp;<span th:text='${btn.btnname}'></span></a></li></ul>
	</div>
	<div id='common-dialog' class='easyui-dialog' modal='true' closed='true' style='display:none;width:325px;height:350px'>
		<div class='easyui-layout' fit='true'>
			<form id='common-form' class='easyui-form' method='post'>
				<input type='hidden' name='id'/>
				<div region='center' border='false'>
				<div class='centerdiv'>
				<table>
					<tr><td><label>代理名称：</label>
					<input class='easyui-textbox' name='orgname' data-options='required:true'/></td></tr>
					<tr><td><label>联系方式：</label>
					<input class='easyui-textbox' name='orgphone' data-options="required:true,validType:['mobile']"/></td></tr>
					<tr><td><label>联系邮箱：</label>
					<input class='easyui-textbox' name='orgemail' data-options="required:true,validType:['email']"/></td></tr>
					<tr><td><label>联系地址：</label>
					<input class='easyui-textbox' name='address' data-options='required:true'/></td></tr>
					<tr><td><label>备注信息：</label>
					<input class='easyui-textbox' name='remark'/></td></tr>
				</table></div></div>
				<div region='south' border='false' class='southdiv'>
				<a class='easyui-linkbutton' icon='fa fa-check-square-o' href='#' onclick="common_submit(-1,'',1)">保存</a>
				<a class='easyui-linkbutton' icon='fa fa-undo' href='#' onclick='common_reset()'>重置</a>
	</div></form></div></div>
	<!-- 账户余额充值 -->
	<div id='balance-dialog' class='easyui-dialog' title='代理余额充值' modal='true' closed='true' 
			style='display:none;width:300px;height:300px'>
		<div class='easyui-layout' fit='true'>
			<form id='balance-form' class='easyui-form' method='post'>
				<input type='hidden' name='id'/>
				<div region='center' border='false'>
				<div class='centerdiv'>
				<table>
					<tr><td><label>代理名称：</label>
					<input class='easyui-textbox' name='orgname' id='orgname' editable="false"/></td></tr>
					<tr><td><label>预付款(分)：</label>
					<input class='easyui-textbox' name='cgemoney' data-options='required:true'/></td></tr>
					<tr><td><label>操作备注：</label>
					<input class='easyui-textbox' name='oprtdesc' data-options='required:true'/></td></tr>
				</table></div></div>
				<div region='south' border='false' class='southdiv'>
				<a class='easyui-linkbutton' icon='fa fa-check-square-o' href='#' onclick="balance_submit()">提交</a>
				<a class='easyui-linkbutton' icon='fa fa-undo' href='#' onclick='balance_cancel()'>取消</a>
	</div></form></div></div>
	
	<table id='common-table'></table>
	<script type='text/javascript' src='jquery.min.js'></script>
	<script type='text/javascript' src='jquery.easyui.min.js'></script>
	<script type='text/javascript' src='js/util.js'></script>
	<script type="text/javascript" src='js/validate.js'></script>
	<script type="text/javascript" src="js/datagrid-detailview.js"></script>
	<script>
		$(function(){
			$('#common-table').treegrid({
				border:false,
				rownumbers: true,
				fitColumns: true,
				fit:true,
				url: '/d/orglist',
				method: 'post',
				idField: 'id',
				treeField: 'orgname',
				striped : true,
				pagination:true,
				pageSize:25,
				pageList:[25,50],
				toolbar:'#toolbar',
				singleSelect:true,
				columns:[[
					{title:'代理名称',field:'orgname',align:'left',width:100},
					{title:'代理标识',field:'id',align:'center',width:100},
					{title:'联系方式',field:'orgphone',align:'center',width:100},
					{title:'联系邮箱',field:'orgemail',align:'center',width:100},
					{title:'联系地址',field:'address',align:'center',width:100},
					{title:'押金（元）',field:'deposit',align:'center',width:100,
						formatter: function(value,row,index){
							return value/100;
						}	
					},
					{title:'代理余额（元）',field:'balance',align:'center',width:100,
						formatter: function(value,row,index){
							return value/100;
						}	
					},
					{title:'返利（元）',field:'benefit',align:'center',width:100,
						formatter: function(value,row,index){
							return value/100;
						}	
					},
					{title:'备注信息',field:'remark',align:'center',width:100},
					{title:'创建时间',field:'crttm',align:'center',width:200,formatter:formatDate},
				]],
				onClickRow:function(row){
					$('#common-table').treegrid('expandAll', row.id);
				}
			})
		});
		function add(){
			common_add('新增','/d/orgsave');
		}
		function edit(){
			common_edit('编辑','/d/orgedit');
		}
		function del(){
			common_delete('/d/orgdel',2,'包含下级，不可删除！',1);
		}
		
		function balance_charge(){
			var row = $('#common-table').treegrid('getSelected');
			if (row == null) {
				$.messager.alert('提示', '请先选择一个代理商,再进行充值操作 !','info');
				return;
			}else{
				$('#balance-form').form('load',row);
				$("#balance-form").attr("action","/d/recharge");
				$("#balance-dialog").dialog("open")
			}
		}	
		
		function balance_submit(){
	        $('#balance-form').form('submit',{
	            onSubmit:function(){
	            	if($(this).form('validate'))
	                return $(this).form('enableValidation').form('validate');
	            },
	    	    success:function(data){
	   	    		$("#balance-form").form("clear");
	       	    	$('#common-table').treegrid('load');
	       	    	$(".panel-tool-close").trigger("click");
	       	    	if(0==data){
		       	    	$.messager.alert('提示','操作成功！','info');
    	    		}else if(1==data){
    	    			$.messager.alert('提示','只能给下级代理充值！','info');
    	    		}else if(2==data){
    	    			$.messager.alert('提示','请输入有效的充值金额！','info');
   	    			}else if(3==data){
    	    			$.messager.alert('提示','本级预付款余额不足！','info');
    	    		}else{
    	    			$.messager.alert('提示','操作失败，请联系管理员！','info');
    	    		}
	    	    }
	        });
	    }
	    function balance_cancel(){
	    	$("#balance-form").form("clear");
	    	$(".panel-tool-close").trigger("click");
		}
	</script>
</body>
</html>
